<template>
  <div>
    <el-input v-model="search"/>
    <my-tree ref="myTree" :filter-node-method="filterNode" :data="stTree" :props="props" @item-click="handleItemClick"/>
  </div>
</template>

<script>
import commonMixins from "@/mixins/commonMixins";
import {mapState} from 'vuex'
import MyTree from "@/components/MyTree";

export default {
  components: {MyTree},
  mixins: [commonMixins],
  name: "SelectBl",
  data() {
    return {
      props: {
        label: 'label',
      },
      search: ''
    }
  },
  computed: {
    ...mapState(['stTree'])
  },
  watch: {
    search() {
      this.$refs.myTree.filter(this.search)
    }
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data[this.props.label].indexOf(value) !== -1;
    },
    expandSt(st) {
      this.$set(st, 'expanded', !st.expanded)
    },
    handleItemClick(item) {
      if (item.parent) {
        this.$emit('select', item, item.parent)
      }
    }
  }
}
</script>
